// sm3.h  
#ifndef SM3_H  
#define SM3_H  

#include <stdint.h> // 使用固定宽度的整数类型  

#ifdef __cplusplus  
extern "C" {  
#endif  

typedef struct {  
    uint32_t total[2];     // 消息总长度（以位为单位）  
    uint32_t state[8];     // 哈希状态  
    unsigned char buffer[64]; // 数据缓冲区  

    // 用于 HMAC  
    unsigned char ipad[64];  
    unsigned char opad[64];  
} sm3_context;  

// SM3 函数  
void sm3_starts(sm3_context *ctx);  
void sm3_update(sm3_context *ctx, const unsigned char *input, int ilen);  
void sm3_finish(sm3_context *ctx, unsigned char output[32]);  
void sm3(const unsigned char *input, int ilen, unsigned char output[32]);  
int sm3_file(const char *path, unsigned char output[32]);  

// SM3 HMAC 函数  
void sm3_hmac_starts(sm3_context *ctx, const unsigned char *key, int keylen);  
void sm3_hmac_update(sm3_context *ctx, const unsigned char *input, int ilen);  
void sm3_hmac_finish(sm3_context *ctx, unsigned char output[32]);  
void sm3_hmac(const unsigned char *key, int keylen,  
             const unsigned char *input, int ilen,  
             unsigned char output[32]);  

#ifdef __cplusplus  
}  
#endif  

#endif // SM3_H